package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.api.model.dto.common.CommonIdListDTO;
import com.ssy.lingxi.platform.manage.api.model.vo.shop.ShopVO;
import com.ssy.lingxi.platform.manage.entity.base.Shop;
import com.ssy.lingxi.platform.manage.model.request.shop.BiddingShopRequest;
import com.ssy.lingxi.platform.manage.model.request.shop.DoorTypeRequest;
import com.ssy.lingxi.platform.manage.model.request.shop.ShopListRequest;
import com.ssy.lingxi.platform.manage.model.request.shop.SiteIdAndEnvironmentRequest;
import com.ssy.lingxi.platform.manage.model.response.EnterpriseShopListResponse;
import com.ssy.lingxi.platform.manage.service.IShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 商城
 * @author fhj
 * @version 2.0.0
 * @date 2020/9/17
 */
@Api(tags = "商城")
@RestController
@RequestMapping("/manage/shop")
public class ShopController extends BaseController {

    @Resource
    private IShopService shopService;
    @Resource
    private HttpServletRequest httpServletRequest;

    /**
     * 判断是否开启Mro模式
     *
     * @param shopId 商城id
     * @return 操作结果
     */
    @GetMapping("/openMro")
    public Wrapper<Boolean> openMro(@RequestParam("shopId") Long shopId) {
        return shopService.openMro(shopId);
    }

    @ApiOperation(value = "查询所有商城信息")
    @GetMapping("/all")
    public Wrapper<List<ShopVO>> shopAll() {
        return shopService.shopAll();
    }

    @ApiOperation(value = "根据商城类型查询商城信息")
    @GetMapping("/all/by/shop/type")
    public Wrapper<List<ShopVO>> shopAllByShopType(@RequestParam("shopType") Integer shopType) {
        return shopService.shopAllByShopType(shopType);
    }

    @ApiOperation(value = "根据商城类型和环境查询商城信息")
    @GetMapping("/findAllByShopTypeAndEnvironment")
    public Wrapper<List<ShopVO>> findAllByShopTypeAndEnvironment(@RequestParam("shopType") Integer shopType, @RequestParam("environment") Integer environment) {
        return shopService.findAllByShopTypeAndEnvironment(shopType, environment);
    }

    @ApiOperation(value = "根据ID查询商城信息")
    @GetMapping("/details")
    public Wrapper<ShopVO> shopDetails(@RequestParam(value = "id") Long id) {
        return shopService.shopDetails(id);
    }

    @ApiOperation(value = "根据站点id查询所有商城信息")
    @GetMapping("/findShopsBySiteId")
    public Wrapper<List<Shop>> findShopsBySiteId(Long siteId, Integer type) {
        return shopService.findShopsBySiteId(siteId, type);
    }

    @ApiOperation(value = "根据站点ID和商城环境查询所有商城信息")
    @GetMapping("/findShopsBySiteIdAndEnvironment")
    public Wrapper<List<Shop>> findShopsBySiteIdAndEnvironment(@Valid SiteIdAndEnvironmentRequest request) {
        return shopService.findShopsBySiteIdAndEnvironment(request);
    }

    @ApiOperation(value = "根据门户类型获取商城【店铺、渠道、采购、物流、加工】")
    @GetMapping("/findByDoorType")
    public Wrapper<List<Shop>> findByDoorType(DoorTypeRequest request) {
        return shopService.findByDoorType(request, httpServletRequest);
    }

    @ApiOperation(value = "根据当前登录会员类型获取商城")
    @GetMapping("/findByMemberType")
    public Wrapper<List<Shop>> findByMemberType() {
        return shopService.findByMemberType(getSysUser());
    }

    @ApiOperation(value = "根据商城ID集合获取商城")
    @PostMapping("/byIdList")
    public Wrapper<List<ShopVO>> shopByIdList(@RequestBody @Valid CommonIdListDTO request) {
        return shopService.shopByIdList(request);
    }

    @ApiOperation(value = "商城列表（装修）")
    @GetMapping("/listAdorn")
    public Wrapper<List<Shop>> listAdorn(@Valid ShopListRequest request) {
        return shopService.listAdorn(request);
    }

    @ApiOperation(value = "采购竞价单- 根据待新增竞价单需要发布的商城类型返回商城信息")
    @GetMapping("/findShopsByShopType")
    public Wrapper<List<Shop>> findShopsByShopType(@Valid BiddingShopRequest request, HttpServletRequest httpServletRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(httpServletRequest);
        return shopService.findShopsByShopType(request, sysUser);
    }

    /**
     * 查询当前站点下企业商城类型的商城
     * @param siteId 站点id
     * @return 商城列表
     */
    @GetMapping("/listEnterpriseShopBySite")
    public Wrapper<List<EnterpriseShopListResponse>> listEnterpriseShopBySite(@RequestParam("siteId") Long siteId){

        return shopService.listEnterpriseShopBySite(siteId,this.getSysUser());
    }

}
